//
//  TouchEvent.hpp
//  cali
//
//  Created by Fan Qu on 10/14/19.
//  Copyright © 2019 GF. All rights reserved.
//

#ifndef TouchEvent_hpp
#define TouchEvent_hpp

#include "utils.h"

enum TouchType {TouchNoneType = 0, TouchDownType = 1, TouchMoveType = 2, TouchUpType = 3};

struct TouchPoint {
    Pos2F pos;
    int id;
    std::vector<std::chrono::time_point<std::chrono::high_resolution_clock> > historyClocks;
    std::vector<Pos2F> historyPoses;

    std::vector<Pos2F> trace;
    TouchPoint(Pos2F pos, int id): pos(pos), id(id) {}
    TouchPoint() {}
};

Pos2F getMoveVec(const TouchPoint& point);

class TouchEvent {
protected:
    int pointID;
    TouchType touchType;
public:
    TouchEvent(int pointID, TouchType type = TouchNoneType): pointID(pointID), touchType(type) {}
    void setPointID(int id) {
        this->pointID = id;
    }
    
    int getPointID() {
        return this->pointID;
    }
    
    void setTouchType(TouchType type) {
        this->touchType = type;
    }
    
    TouchType getTouchType() {
        return this->touchType;
    }

};

class TouchDown : public TouchEvent {

protected:
    double x, y;
    TouchPoint point;
public:
    TouchDown(int pointID, double x, double y, TouchPoint touchPoint): TouchEvent(pointID, TouchDownType), x(x), y(y), point(touchPoint) {}
    double getX() {
        return x;
    }
    double getY() {
        return y;
    }

    void setX(double x) {
        this->x = x;
    }

    void setY(double y) {
        this->y = y;
    }

    Pos2F getPos() {
        return Pos2F(x, y);
    }

    TouchPoint getTouchPoint() {
        return point;
    }
    
};

class TouchMove: public TouchEvent {
protected:
    TouchPoint point;
    
public:
    TouchMove(int pointID, TouchPoint touchPoint): TouchEvent(pointID, TouchMoveType), point(touchPoint) {}
    
    TouchPoint getTouchPoint() {
        return point;
    }
};

class TouchUp: public TouchEvent {
protected:
    TouchPoint point;
public:
    TouchUp(int pointID, TouchPoint touchPoint): TouchEvent(pointID, TouchUpType), point(touchPoint) {}
    
    TouchPoint getTouchPoint() {
        return point;
    }
};

#endif /* TouchEvent_hpp */
